<template>
  <el-card>
    <el-form ref="form"
      :model="form"
      :rules="rules"
      label-position="left"
      label-width="100px">
      <el-form-item label="姓名"
        prop="name">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>
      <el-form-item label="员工账号"
        prop="account">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>
      <el-form-item label="员工密码"
        prop="password">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>

      <el-form-item label="部门职位"
        prop="post">
        <el-select v-model="form.post"
          :class="$style.formInput"></el-select>
      </el-form-item>
      <el-form-item label="性别"
        prop="sex">
        <el-radio-group v-model="form.sex">
          <el-radio :label="1">男</el-radio>
          <el-radio :label="2">女</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="手机号码"
        prop="phone">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>
      <el-form-item label="家庭住址"
        prop="address">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>
      <el-form-item label="出生时间"
        prop="birth">
        <el-input :class="$style.formInput"></el-input>
      </el-form-item>
      <el-form-item label="入职时间"
        prop="date">
        <el-date-picker v-model="form.date"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
          :class="$style.formInput">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button @click="clear">取 消</el-button>
        <el-button type="primary"
          @click="submit">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        account: [
          { required: true, message: '请输入员工账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入员工密码', trigger: 'blur' }
        ],
        post: [{ required: true, message: '请选择部门职位', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
        address: [
          { required: true, message: '请输入家庭住址', trigger: 'blur' }
        ],
        birth: [{ required: true, message: '请输入出生时间', trigger: 'blur' }],
        date: [{ required: true, message: '请选择入职时间', trigger: 'blur' }]
      }
    }
  },

  methods: {
    submit() {
      this.$refs.form.validate(valid => {
        if (!valid) return
      })
    },

    clear() {
      this.form = {}
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style module lang="scss">
.formInput {
  width: 250px !important;
}
</style>
